﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：执行日志
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var keyValue = request("keyValue");
    var companyId= request("companyId");

    var page = {
        init: function () {
            page.bind();
            page.initGrid();
            page.search();
        },
        bind: function () {
            // 搜索框初始化
            $('#keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

        },

        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'auditmodelwarnlogs/list?companyId=' + companyId + '&modelId=' + keyValue + '&access_token=' + config.getToken().access_token,
                headData: [
                     {
                        label: "模型名称", name: "modelName", width: 260, align: "left",
                    },
                    {
                        label: "执行结果", name: "excuteResult", width: 120, align: "center",
                        formatter: function (value) {
                            if (value == '1') {
                                 return "<span style='color:blue;'>成功</span>";
                            } else {
                                 return "<span style='color:red;'>失败</span>";
                            }
                        }
                    },
                    {
                        label: "执行结果", name: "resultUrl", width: 550, align: "left",
                    },
                    {
                        label: "操作", name: "btn2", width: 180, align: "center",
                        formatter: function (value, row, op, $cell) {
                            $cell.on('click', '.previewResult', function () {
                                if ($cell.html().trim() == '') {
                                    return false;
                                }
                                var code = row.modelId;
                                var keyValue = row.modelId;
                                var modelName = row.modelName;
                                if (learun.checkrow(keyValue)) {
                                    learun.layerForm({
                                        id: 'preview_result' + keyValue,
                                        title: '预览结果集',
                                        url: config.webportal_server + 'pages/finance/audit_rule/preview_result/result' + code + '.html?companyId=' + companyId + '&modelId=' + keyValue + '&access_token=' + config.getToken().access_token,
                                        width: 1000,
                                        height: 800,
                                        maxmin: true,
                                        btn: null
                                    });
                                }
                                return false;
                            });
                            return '<span class="label label-info previewResult" style="cursor: pointer;">预览</span>';
                        }
                    },
                    {
                       label: "执行时间", name: "createTime", width: 140, align: "center",
                       formatter: function (value) {
                           return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                       }
                   },
                   {label: "id", name: "id", width: 250, align: "center",hidden: true},
                ],
                mainId: 'id',
                isPage: true,
                reloadSelected: true,
                isTree: false,
            });
        },
        search: function (param) {
            param = param || {};
            var keyword = $("#keyword").val();
            param.companyId = companyId;
            param.keyword = keyword;
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


